package com.whale.mq.rabbit;

import com.whale.mq.service.ConsumeService;
import com.whale.service.OrderService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

@Component
public class RabbitMqReceiver {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private ConsumeService consumeService;


    /**
     * 消息监听方法，接收订单支付成功通知。
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "${whale.rabbitmq.queues}", durable = "true"),
            exchange = @Exchange(value = "${whale.rabbitmq.exchange.name}", type = ExchangeTypes.TOPIC),
            key = "${whale.rabbitmq.routing.key}"
    ))
    public void receivePaymentSuccessNotification(Message outTradeNo){
        String message = new String(outTradeNo.getBody());
        // 处理订单支付成功逻辑
        consumeService.consumerRabbit(message);
    }

}